
$(document).ready(function() {
    var Main = {
        data() {
            return {
                tableData: [],
                qishu: 30
            };
        },
        created() {
            // 组件实例初始化完成后立即调用
            this.getFucai3dListByStartId(this.qishu);
        },
        methods: {
            cellStyle({ row, column, rowIndex, columnIndex }) {
                // 判断单元格内容是否为"正确"
                if (row[column.property] === '正确') {
                    return 'color: green';
                }else if (row[column.property] === '不正确') {
                    return 'color: red';
                }
                return ''; // 默认不设置样式
            },
            // 获取近多少期数据
            getFucai3dListByStartId(quantity){
                let _this = this;
                $.ajax({
                    type: "GET",
                    url: "http://localhost:8809/fucai/3d/getFucai3dListByStartId",
                    data: {
                        "quantity": quantity
                    },
                    success: function (response) {
                        console.log("请求成功:", response);
                        _this.tableData = response;
                        _this.addNewShuzi()
                    }
                });
            },
            // 切换期数
            swapDates(qishu){
                this.qishu = qishu;
                this.getFucai3dListByStartId(qishu);
            },
            addNewShuzi(){
                // 最新一期数据
                let lastData = this.tableData[this.tableData.length-1];
                // 倒数第二期数据
                let last2Data = this.tableData[this.tableData.length-2];

                // 根据最新数据生成下一期期号
                const newQihaoNian = String(lastData.qihao).substring(0, 4);
                const newQihao = String(Number(String(lastData.qihao).substring(4, 7)) + 1).padStart(3, '0');
                let newQihaoAll = newQihaoNian + newQihao;

                // 最新开奖日期
                const newKjDate = addOneDay(lastData.kjDate);
                let kjDateWeiSha = newKjDate.substring(9, 10);

                let shang2ShiHezhiWei = (Number(lastData.zjS) + Number(last2Data.zjS)) % 10;
                let kj = '169';
                let kjKuadu = Math.max(kj.charAt(0), kj.charAt(1), kj.charAt(2)) - Math.min(kj.charAt(0), kj.charAt(1), kj.charAt(2));
                let sj = '';
                let sjKuadu = Math.max(sj.charAt(0), sj.charAt(1), sj.charAt(2)) - Math.min(sj.charAt(0), sj.charAt(1), sj.charAt(2));
                let newData = {
                    "qihao": newQihaoAll,
                    "kjDate": newKjDate,
                    "kjDateWeiSha": kjDateWeiSha,
                    "kj": kj,
                    "sj": sj,
                    "sqHezhiWeiSha": lastData.hezhiWei,
                    "sqKuaduSha": lastData.kuadu,
                    "qihaoWeiSha": (Number(lastData.qihaoWei) + 1) % 10,
                    "shang2ShiHezhiWeiSha": shang2ShiHezhiWei,
                    "kjHeweiSha": (Number(kj.charAt(0)) + Number(kj.charAt(1)) + Number(kj.charAt(2))) % 10,// 开机和尾
                    "kjKuaduSha": kjKuadu,// 开机跨度
                    "sjHeweiSha": sj ? ((Number(sj.charAt(0)) + Number(sj.charAt(1)) + Number(sj.charAt(2))) % 10) : '',// 试机和尾
                    "sjKuaduSha": sj ? sjKuadu : '',// 试机跨度
                    "baiwei3Sha": (lastData.zjB * 3 + 3) % 10,// 百位*3+3
                    "baiwei7Sha": (lastData.zjB * 7 + 7) % 10 // 百位*7+7
                }
                this.tableData.push(newData);
            }
        }
    };

    var Ctor = Vue.extend(Main)
    new Ctor().$mount('#app')
});

function addOneDay(dateStr) {
    // 提取日期部分（如"2025-09-03"）
    const datePart = dateStr.match(/\d{4}-\d{2}-\d{2}/)[0];

    // 创建日期对象并加一天
    const date = new Date(datePart);
    date.setDate(date.getDate() + 1);

    // 定义星期几的中文表示
    const weekdays = ['日', '一', '二', '三', '四', '五', '六'];

    // 格式化新日期
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const weekday = weekdays[date.getDay()];

    return `${year}-${month}-${day}(${weekday})`;
}